package com.ruoyi.yuce.service.impl;

import com.ruoyi.yuce.domain.YcData;
import com.ruoyi.yuce.domain.YcDataCeshi;
import com.ruoyi.yuce.mapper.YcDataCeshiMapper;
import com.ruoyi.yuce.service.IYcDataCeshiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 电度表Service业务层处理
 */
@Service
public class YcDataCeshiServiceImpl implements IYcDataCeshiService
{
    @Autowired
    private YcDataCeshiMapper ycDataCeshiMapper;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    /**
     * 查询遥测列表
     */
    @Override
    public List<YcDataCeshi> selectYcDataList(YcDataCeshi ycDataCeshi) {

        // return ycDataCeshiMapper.selectYcDataList(ycDataCeshi);

        List<YcDataCeshi> ycDataCeshiList = ycDataCeshiMapper.selectYcDataList(ycDataCeshi);    //获取遥测数据
        List<YcDataCeshi> resultList = new ArrayList<>();   //新建转换成的遥测数据列表

        float h[] = new float[24];      //24小时参数数据值

        for (YcDataCeshi yc : ycDataCeshiList) {       //每一列的数据
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(yc.getRiqi());

            // 获取每小时的参数数据
            h[0] = yc.getH0();
            h[1] = yc.getH1();
            h[2] = yc.getH2();
            h[3] = yc.getH3();
            h[4] = yc.getH4();
            h[5] = yc.getH5();
            h[6] = yc.getH6();
            h[7] = yc.getH7();
            h[8] = yc.getH8();
            h[9] = yc.getH9();
            h[10] = yc.getH10();
            h[11] = yc.getH11();
            h[12] = yc.getH12();
            h[13] = yc.getH13();
            h[14] = yc.getH14();
            h[15] = yc.getH15();
            h[16] = yc.getH16();
            h[17] = yc.getH17();
            h[18] = yc.getH18();
            h[19] = yc.getH19();
            h[20] = yc.getH20();
            h[21] = yc.getH21();
            h[22] = yc.getH22();
            h[23] = yc.getH23();

            for (int i=0;i<24;i++){

                Calendar calendarSet = Calendar.getInstance();
                calendarSet.setTime(calendar.getTime());
                calendarSet.add(Calendar.HOUR_OF_DAY,i);
                YcDataCeshi newObject = new YcDataCeshi(yc);
                Date newriqi = calendarSet.getTime();      // 获取calendar对象对应的Date对象
                newriqi = new Date(newriqi.getTime());  // 创建一个新的Date对象，其时间戳与newriqi相同，但两者指向不同地址
                newObject.setRiqi(newriqi);
                newObject.setBujiancanshu(h[i]);
                resultList.add(newObject);      //将newObject添加到resultList



                /**

                 YcDataCeshi newObject = new YcDataCeshi(yc);

                 Date newriqi = calendar.getTime();      // 获取calendar对象对应的Date对象
                 newriqi = new Date(newriqi.getTime());  // 创建一个新的Date对象，其时间戳与newriqi相同，但两者指向不同地址

                 newObject.setRiqi(newriqi);
                 newObject.setBujiancanshu(h[i]);
                 resultList.add(newObject);      //将newObject添加到resultList

                 calendar.add(Calendar.HOUR_OF_DAY,1);

                 */

            }
        }
        return resultList;

    }


}
